# -*- conding:UTF-8 -*-

'''
@ Project: p7_flask
@ File: create_app.py
@ Author: 师路遥
@ Date：2022/6/6 13:27

'''

from flask import Flask
from flask_cors import CORS
from models import db
from views.users import user_bp
from views.comments import comment_bp
from views.channel import channel_bp
from common.utils.jwt_auth import jwt_authentication

def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    # 初始化
    db.init_app(app)
    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(comment_bp)
    app.register_blueprint(channel_bp)

    # 使用请求钩子验证token
    app.before_request(jwt_authentication)
    # 配置跨域
    cors = CORS(app)

    return app